﻿Imports System.ComponentModel

Public Class ResultsItem
    Implements INotifyPropertyChanged

    Private mClassName As String
    Public Property ClassName As String
        Get
            Return mClassName
        End Get
        Set(ByVal Value As String)
            If mClassName <> Value Then
                mClassName = Value
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("ClassName"))
            End If
        End Set
    End Property

    Private mCounts As New List(Of Long)
    Public Property Counts As List(Of Long)
        Get
            Return mCounts
        End Get
        Set(ByVal Value As List(Of Long))
            mCounts = Value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Counts"))
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("CountString"))
        End Set
    End Property

    Public ReadOnly Property CountChangePercent() As Double
        Get
            If mCounts.Count <= 1 Then Return 0.0
            Dim lastIndex As Integer = mCounts.Count - 1

            'handle the zero cases
            If mCounts.Item(0) = 0 AndAlso mCounts.Item(lastIndex) = 0 Then Return 0
            If mCounts.Item(0) = 0 Then Return 100
            If mCounts.Item(lastIndex) = 0 Then Return -100

            Return Math.Round((mCounts.Item(lastIndex) - mCounts.Item(0)) / mCounts.Item(0), 1)
        End Get
    End Property

    Private mSizes As New List(Of Long)
    Public Property Sizes As List(Of Long)
        Get
            Return mSizes
        End Get
        Set(ByVal Value As List(Of Long))
            mSizes = Value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Sizes"))
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("SizeString"))
        End Set
    End Property

    Public ReadOnly Property SizeChangePercent() As Double
        Get
            If mSizes.Count <= 1 Then Return 0.0
            Return Math.Round((mSizes.Item(mSizes.Count - 1) - mSizes.Item(0)) / mSizes.Item(0), 1)
        End Get
    End Property

    Private mCountString As String
    Public ReadOnly Property CountString As String
        Get
            If mCounts Is Nothing OrElse mCounts.Count = 0 Then Return String.Empty
            Dim bld As New System.Text.StringBuilder
            Dim seperator As String = Nothing
            For Each i As Long In mCounts
                If bld.Length > 0 AndAlso String.IsNullOrEmpty(seperator) Then
                    seperator = " > "
                End If
                bld.AppendFormat("{0}{1}", seperator, i)
            Next
            Return bld.ToString
        End Get
    End Property

    Private mSizeString As String
    Public ReadOnly Property SizeString As String
        Get
            If mSizes Is Nothing OrElse mSizes.Count = 0 Then Return String.Empty
            Dim bld As New System.Text.StringBuilder
            Dim seperator As String = Nothing
            For Each i As Long In mSizes
                If bld.Length > 0 AndAlso String.IsNullOrEmpty(seperator) Then
                    seperator = " > "
                End If
                bld.AppendFormat("{0}{1}", seperator, i)
            Next
            Return bld.ToString
        End Get
    End Property

    Private mMT As String
    Public Property MT As String
        Get
            Return mMT
        End Get
        Set(ByVal Value As String)
            If mMT <> Value Then
                mMT = Value
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("MT"))
            End If
        End Set
    End Property




    Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
